<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=640px,user-scalable=no,target-densitydpi=device-dpi" />
		<link rel="stylesheet" href="../css/css.css" type="text/css" />
		<script type="text/javascript" src='../js/jquery.min.js'></script>
		<script type="text/javascript" src='../js/main_in.js'></script>
		<script type="text/javascript" src='../js/common.js'></script>
		<title>客户修改</title>
		<script type="text/javascript">
			var hid = getUrlParam('hid');
			
			$(function(){
				cust_search()
			});
			
			function doedit(){
				var Name = $("#passenger_fullname").val();
                   var ContactTel = $("#passenger_tel").val();
                   var Contact = $("#passenger_contact").val();
                   var CityID = $("#CityID").val();
                   var CityName  = $("#CityName").val();
                   var Address = $("#Address").val();
                   
                   if(Name == ''){
                       alert_error("客户名称不能为空");
                        return false;
                   }
                   
                   if(CityName == ''){
                       alert_error("客户地址不能为空");
                        return false;
                   }
                   
                   if(Address == ''){
                       alert_error("详细地址不能为空");
                        return false;
                   }
                   
                   if(Contact == ''){
                       alert_error("联系人不能为空");
                        return false;
                   }
                   
                   if(ContactTel == ''){
                       alert_error("联系方式不能为空");
                        return false;
                   }
                   var body = {
                       "Type":"10","Name":Name,"Tel":'',"NDID":"63599-70527","Email":"","Fax":"","Contact":Contact,"ContactTel":ContactTel,"Sales":"","InvoiceType":"10","Remark":"","Img":"","CPID":"11583-47254","Token":"22e8f734-dae9-494e-a743-4c4a64af4ce2",
                       "Users":{"id":35369,"username":"44827-Admin","cpid":"11583-47254","cpname":"\u5361\u822a\u7f51\u7edc","ndid":"63599-70527","ndname":"\u5361\u822a\u7f51\u7edc","cmid":""},
                       "CityID":CityID,"CityName":CityName,"Address":Address,"CreateBy":"<?php echo $_SESSION['user']['loginname']; ?>"
                   }
                   
                   if(confirm("确认提交？")){
                   	var wt=plus.nativeUI.showWaiting();
                        $.ajax({
                            url: "http://api.unair.cn/api/CustomerBL?id="+ hid,
                            type: "PUT",
                            data: body,
                            success: function (data) {
                            	wt.close();
                                if(data != null){
                                    
                                    var w=plus.nativeUI.showWaiting("提交成功");
									w.onclose=function(){
										clearInterval(t);
									}
									var t=setInterval(function(){
										w.setTitle("提交成功");
										w.close();
										clicked("addr_search.html?x=1");
										clearInterval(t);
									},2000);
                                }else{
                                    alert("提交失败");
                                }
                            },
                            error: function (data) {
                            	wt.close();
                                alert(JSON.stringify(data))
                            }

                        });
                    };
			}
			
			function cust_search(){
				
				var body = {"TableName": "Customer", "PKName": "ID", "PageSize": "15", 'pageCurrent': 1, "where": " ID = "+hid+" "};

                $.ajax({
                    url: "http://api.unair.cn/api/PagingQuery",
                    type: "POST",
                    data: body,
                    success: function(data) {
                        data = eval("(" + data.ResTable + ")");
                        
                        var item = '';
                        $.each(data, function(k, v) {
                             v.Name = typeof (v.Name) == 'undefined' ? '' : v.Name;
                            v.Name = v.Name == null ? '' : v.Name;
                            v.ContactTel = typeof (v.ContactTel) == 'undefined' ? '' : v.ContactTel;
                            v.ContactTel = v.ContactTel == null ? '' : v.ContactTel;
                            v.Contact = typeof (v.Contact) == 'undefined' ? '' : v.Contact;
                            v.Contact = v.Contact == null ? '' : v.Contact;
                             v.CityName = typeof (v.CityName) == 'undefined' ? '' : v.CityName;
                            v.CityName = v.CityName == null ? '' : v.CityName;
                            v.Address = typeof (v.Address) == 'undefined' ? '' : v.Address;
                            v.Address = v.Address == null ? '' : v.Address;
                            $("#passenger_fullname").val(v.Name);
                            $("#CityName").val(v.CityName);
                            $("#Address").val(v.Address);
                            $("#CityID").val(v.CityID);
                            $("#passenger_contact").val(v.Contact);
                            $("#passenger_tel").val(v.ContactTel);
                        });
                        $(".main_s1").find('.main_in_tr_head').after(item);
                    },
                    error: function(data) {
                        alert(JSON.stringify(data))
                    }
                });
			}
		</script>
	</head>
	<body>
		<div class="app_head">
            <div class="app_prev" onclick="back()"><img src="../img/arrow.png" /></div>
            <div class="app_head_text">客户修改</div>
            <div class="app_prev"></div>
        </div>
        <div class="app_body">
            <div class="main_in_input">
                <div class="main_in_input_text_left">客户名称：</div>
                <div class="main_in_input_input_right"><input type="text" id="passenger_fullname" value="" /></div>
            </div>
            <div class="main_in_input">
                <div class="main_in_input_text_left">客户地址：</div>
                <div class="main_in_input_input_right"><input type="text" class="select_city" id="CityName" value=""  readonly="true" /></div>
                <input type="hidden" name="CityID" class="select_city_id" id="sub_cityid" />
            </div>
            <div class="main_in_input">
                <div class="main_in_input_text_left">详细地址：</div>
                <div class="main_in_input_input_right"><input type="text" id="Address" value="" /></div>
            </div>
            <div class="main_in_input">
                <div class="main_in_input_text_left">联系人：</div>
                <div class="main_in_input_input_right"><input type="text" id="passenger_contact" value="" /></div>
            </div>
            <div class="main_in_input">
                <div class="main_in_input_text_left">联系电话：</div>
                <div class="main_in_input_input_right"><input type="text" id="passenger_tel" value="" /></div>
            </div>
            <div style="background: #fff;width: 100%;height: 100px;">
                <div class="bg_submit" onclick="doedit()">提&nbsp;交</div>
                <div class="bg_back_class" onclick="back()">取&nbsp;消</div>
            </div>
        </div>
        
<div class="outside_pull"></div>
<img src="../img/loading.gif" class="fade_out_img" id="fade_out_loading" />
	</body>
</html>
